//
//  ViewController.m
//  DemoNativeAd
//
//  Created by houshunwei on 15-6-9.
//  Copyright (c) 2015年 baidu. All rights reserved.
//

#import "LSZBStationPlayingInterfaceVC.h"
#import "LSZBStationPlayingInterfaceVC+LCMorePicturesTable.h"

@interface LSZBStationPlayingInterfaceVC ()

@end

@implementation LSZBStationPlayingInterfaceVC

- (void)viewDidLoad
{
    [super viewDidLoad];
//    //设置开发者自己处理View点击事件,只需要设置一次，不设置时，sdk内部采用默认方式处理
//    [BaiduMobAdNativeAdView dealTapGesture:true];
    self.tableViewList = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-0) style:UITableViewStylePlain] ;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.tabBarController.tabBar.translucent = NO;
    self.tableViewList.delegate = self;
    self.tableViewList.dataSource = self;
    [self.view addSubview:self.tableViewList];
    
    [self.tableViewList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCellIdentifier"];
    ///请求广告
    [self pressToLoadAd];
}


- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
        self.native.delegate = nil;
        self.native = nil;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.adViewArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 351/2+40;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCellIdentifier" forIndexPath:indexPath];
    if (self.adViewArray.count > indexPath.row)
    {
        BaiduMobAdNativeAdView *view = [self.adViewArray objectAtIndex:indexPath.row];
        view.tag = 0;
        [[cell viewWithTag:0] removeFromSuperview];
        [cell addSubview:view];
        view.frame =
        CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width-10, 351/2+40);

        [self sendVisibleImpressionAtIndexPath:indexPath];
    }
    return cell;
}

- (void)dealloc {
    _native = nil;
    for (UIView *adview in _adViewArray) {
        [adview removeFromSuperview];
    }
    [_adViewArray removeAllObjects];
    _adViewArray = nil;
    _adsArray = nil;
}

@end
